﻿Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL


Public Class Consultar_Tarifa

    'Inherits System.Web.UI.Page
    Inherits PaginaBase

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Not Page.IsPostBack Then
        '    txtNave.Text = "" : txtPto.Text = "" : txtNroBl.Text = "" : lblKvje.Text = 0
        'End If
        'If My.Request.Params("__EVENTTARGET") = "MiFuncionPaquetes" Then
        '    CargarDatosViajePopUp()
        'End If
    End Sub

    Public Sub CargarDatosViajePopUp()

        'If Session("BPCodViaje") = Nothing Then
        '    lblKvje.Text = String.Empty
        '    txtNave.Text = String.Empty
        'Else
        '    lblKvje.Text = Session("BPCodViaje")
        '    txtNave.Text = Session("BPDesViaje")
        'End If
    End Sub

    Protected Sub btnGrabar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        CargarGridConsulta()
    End Sub

    Public Sub CargarGridConsulta()
        Dim objTarifaFleteBE As New TarifaFleteBE
        Dim lstBlImpoBE As New List(Of TarifaFleteBE)
        Dim objUtil As New Funciones
        Dim objTarifaFleteBC As New TarifaFleteBC

        'validar fechas 

        Dim fechasIni As String = txtFecIni.Text.Trim
        Dim fechasFin As String = txtFecFin.Text.Trim

        'If DateDiff(DateInterval.Day, CDate(txtFecFin.Text), CDate(txtFecInicio.Text)) > 0 Then
        '    Alerta("La fecha inicial no debe exceder al final.", MsgBoxStyle.Information, "")
        '    Exit Sub
        'End If

        'If (Convert.ToDateTime(txtFecInicio.Text).ToString("dd/MM/yyyy") < Date.Now Or Convert.ToDateTime(txtFecFin.Text).ToString("dd/MM/yyyy") < Date.Now) And Session("TipoEvento") = 0 Then
        '    Alerta("La fecha debe ser mayor a la actual.", MsgBoxStyle.Information, "")
        '    Exit Sub
        'End If

        'If Not IsDate(fechasIni) Then
        '    MsgBox("La fecha de inicio de vigencia no tiene formato DD/MM/YYYY.", MsgBoxStyle.Information, "")
        '    Exit Sub
        'End If

        'If Not IsDate(fechasFin) Then
        '    MsgBox("La fecha de fin de vigencia no tiene formato DD/MM/YYYY.", MsgBoxStyle.Information, "")
        '    Exit Sub
        'End If


        If txtFecIni.Text.Length > 0 Or txtFecFin.Text.Length > 0 Then
            If CDate(txtFecFin.Text) < CDate(txtFecIni.Text) Then
                MsgBox("La fecha final no puede ser menor que la inicial.", MsgBoxStyle.Information, Me.Title)
                'Alerta("La fecha final no puede ser menor que la inicial.", False, String.Empty)
                Exit Sub
            End If
        End If

        objTarifaFleteBE.Tfl_Csne = txtCliente.Text.Trim
        objTarifaFleteBE.Tfl_Tmov = cboTipoMovimiento.SelectedValue
        objTarifaFleteBE.Tfl_Fivig = txtFecIni.Text  'Convert.ToDateTime(txtFecInicio.Text).ToString("dd/MM/yyyy")
        objTarifaFleteBE.Tfl_Ffinvig = txtFecFin.Text ' Convert.ToDateTime(txtFecFin.Text).ToString("dd/MM/yyyy")

        lstBlImpoBE = objTarifaFleteBC.ListarTarifaFlete(objTarifaFleteBE)
        dgTarifaFlete.DataSource = lstBlImpoBE
        dgTarifaFlete.DataBind()


    End Sub


    Protected Sub btnNuevo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNuevo.Click

        Session("TipoTransaccionTarifaFlete") = 0 ' si es nuevo
        Response.Redirect("GestionarTarifa.aspx", True)
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLimpiar.Click

        txtFecFin.Text = ""
        txtFecIni.Text = ""
        txtCliente.Text = ""
    End Sub

    Private Sub dgBlImportacion_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgTarifaFlete.RowCommand

        Try
            Dim sValor As String = e.CommandArgument 'Convert.ToInt32(e.CommandArgument)
            'Dim iViaje As Integer = Val(lblKvje.Text)
            Dim sMensaje As String = String.Empty
            Dim bExito As Boolean

            Select Case e.CommandName  '.ToLower
                Case "Editar"

                    Session("ClienteTarifaFlete") = sValor ' modificar
                    Session("TipoTransaccionTarifaFlete") = 1
                    Response.Redirect("GestionarTarifa.aspx", True)

                Case "Eliminar"

                    Dim objTarifaFleteBE As New TarifaFleteBE
                    objTarifaFleteBE.Tfl_Csne = sValor

                    Dim objTarifaFleteBC As New TarifaFleteBC

                    objTarifaFleteBC.EliminarTarifaFlete(objTarifaFleteBE, bExito, sMensaje)
                    If bExito Then
                        Alerta("El registro fue eliminado con éxito.", False, String.Empty)
                        CargarGridConsulta()
                    End If

            End Select

        Catch ex As Exception
            ex.Message.ToString()
        End Try

    End Sub

    'Protected Sub ASPxButtonEdit1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ASPxButtonEdit1.TextChanged
    '    Response.Redirect("../page/PopUp/BuscarPuerto.aspx", True)
    'End Sub

    Sub Cambiarpagina(ByVal sender As Object, ByVal e As GridViewPageEventArgs)

        Dim objTarifaFleteBE As New TarifaFleteBE
        Dim lstBlImpoBE As New List(Of TarifaFleteBE)
        Dim objUtil As New Funciones
        Dim objTarifaFleteBC As New TarifaFleteBC

        'validar fechas 

        Dim fechasIni As String = txtFecIni.Text.Trim
        Dim fechasFin As String = txtFecFin.Text.Trim

        objTarifaFleteBE.Tfl_Csne = txtCliente.Text.Trim
        objTarifaFleteBE.Tfl_Tmov = cboTipoMovimiento.SelectedValue
        objTarifaFleteBE.Tfl_Fivig = "" 'Convert.ToDateTime(txtFecInicio.Text).ToString("dd/MM/yyyy")
        objTarifaFleteBE.Tfl_Ffinvig = "" ' Convert.ToDateTime(txtFecFin.Text).ToString("dd/MM/yyyy")

        lstBlImpoBE = objTarifaFleteBC.ListarTarifaFlete(objTarifaFleteBE)
        dgTarifaFlete.PageIndex = e.NewPageIndex
        dgTarifaFlete.DataSource = lstBlImpoBE
        dgTarifaFlete.DataBind()


    End Sub

End Class